package com.film.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.film.dao.PerformerDao;
import com.film.dao.impl.PerformerDaoImpl;
import com.film.domain.Film;
import com.film.domain.Performer;
import com.film.service.PerformerService;

public class PerformerServiceImpl implements PerformerService {
	private PerformerDao performerDao = new PerformerDaoImpl();
	@Override
	public List<Performer> selectFilmPerformer(int film_id) {
		
		return performerDao.selectFilmPerformer(film_id);
	}

	@Override
	public List<Film> dirIdSelectFilm(int perId) {
		
		return performerDao.perIdSelectFilm(perId);
	}

	@Override
	public Performer returnPerformerAndFilm(int perId) {
		Performer per = this.selectOneDir(perId);
		per.setFilms(this.dirIdSelectFilm(per.getPerId()));
		return per;
	}

	@Override
	public Performer selectOneDir(int perId) {
		
		return performerDao.selectOnePerformer(perId);
	}

	@Override
	public List<Performer> selectAllPerformer() {
		// TODO Auto-generated method stub
		return performerDao.selectAllPerformer();
	}

	@Override
	public int addFilmPerformer(int filmId, int perId) {
		// TODO Auto-generated method stub
		return performerDao.addFilmPerformer(filmId, perId);
	}




















	@Override
	public int addPerformer(Performer performer) {
		// TODO Auto-generated method stub
		return performerDao.addPerformer(performer);
	}

	@Override
	public int deletePerformer(int per_id) {
		// TODO Auto-generated method stub
		return performerDao.deletePerformer(per_id);
	}

	@Override
	public List<Performer> selectPerformer() {
		
		return performerDao.selectPerformer();
	}

	@Override
	public int updatePerformer(Performer performer) {
		
		return performerDao.updatePerformer(performer);
	}

	@Override
	public List<Performer> selectPerformer(int perId) {
		// TODO Auto-generated method stub
		return performerDao.selectPerformer(perId);
	}

	@Override
	public List pageNum() {
		List<Performer> performers = performerDao.selectPerformer();
		int p = 0;
		int num = 0;
		int count = 0;
		List pageNum = new ArrayList();
		for (Performer performer2 : performers) {
			p++;
			num++;
			if(num%10==0){
				count++;
				num = 0;
				pageNum.add(count);
			}
		}
		if(count*10<p) {
			count++;
			pageNum.add(count);
		}
		return pageNum;
	}

	@Override
	public List<Performer> selectPerformer(int firstPage, int selectPageNum) {
		// TODO Auto-generated method stub
		return performerDao.selectPerformer(firstPage, selectPageNum);
	}

}
